﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;


namespace finalexam
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "欢迎来到学生信息管理系统";
        }

        protected void login_Click(object sender, EventArgs e)
        {
            
            string strCn = "server=pc.hstc.cn;database=dhd2014112134;uid=2014112134;pwd=19951124";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {

                cn.Open();


                    string ID = Request.QueryString["ID"];
                    if (rbStu.Checked)
                    {
                        Session["No"] = this.txtNo.Text;
                        string strSql = "SELECT   UserName, Password  FROM  login  WHERE   (UserName = N'" + txtNo.Text + "') AND (Password = N'" + txtPwd.Text + "')";
                        SqlCommand cmd = new SqlCommand(strSql, cn);
                        SqlDataReader dr = cmd.ExecuteReader();
                        if (dr.Read())
                        {


                            this.txtNo.Text = "SELECT  UserName  FROM  login";
                            this.txtPwd.Text = "SELECT   Password  FROM  login";
                            Response.Redirect("Sempty.aspx");
                        }
                        else
                        {

                            Response.Write("<script>alert('您填写的登录信息有误，请重新填写。');location.href='Default.aspx';</script>");

                        }
                    }
                    else
                    {
                        string strSql = "SELECT   UserName, Password  FROM  UserTea  WHERE   (UserName = N'" + txtNo.Text + "') AND (Password = N'" + txtPwd.Text + "')";
                        SqlCommand cmd = new SqlCommand(strSql, cn);
                        SqlDataReader dr = cmd.ExecuteReader();
                        if (dr.Read())
                        {
                            Session["Tno"] = this.txtNo.Text;//
                            this.txtNo.Text = "SELECT  UserName  FROM  UserTea";
                            this.txtPwd.Text = "SELECT   Password  FROM  UserTea";
                            Response.Redirect("Tempty.aspx");
                        }
                        else
                        {
                             Response.Write("<script>alert('您填写的登录信息有误，请重新填写。');location.href='Default.aspx';</script>");
                            
                        }
                       
                    }
                }

           

            catch (Exception ex)
            {
                this.Label4.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112122;uid=2014112122;pwd=19950123";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                string ID = Request.QueryString["ID"];
                if (rbStu.Checked)
                {
                    Response.Redirect("Register.aspx");
                }
                else
                {
                    Response.Write("<script>alert('无注册权限，请选择正确身份或用指定账号及密码登录，单击“确定”可直接返回。');location.href='Default.aspx';</script>");
                }
            }
            catch (Exception ex)
            {
                this.Label4.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }
    }
}



